package com.hanzhong.travel.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.ResponseEntity;

import java.util.HashMap;
import java.util.Map;

/**
 * 测试控制器
 */
@RestController
@RequestMapping("/api/test")
public class TestController {

    /**
     * 支持OPTIONS请求
     */
    @RequestMapping(method = RequestMethod.OPTIONS)
    public ResponseEntity<?> options() {
        return ResponseEntity.ok().build();
    }

    /**
     * 简单的ping测试，检查API是否可访问
     */
    @GetMapping("/ping")
    public Map<String, Object> ping() {
        System.out.println("收到ping请求");
        Map<String, Object> response = new HashMap<>();
        response.put("message", "pong");
        response.put("timestamp", System.currentTimeMillis());
        return response;
    }

    /**
     * 检查系统环境
     */
    @GetMapping("/env")
    public Map<String, Object> getEnv() {
        System.out.println("收到环境检查请求");
        Map<String, Object> response = new HashMap<>();
        response.put("java.version", System.getProperty("java.version"));
        response.put("os.name", System.getProperty("os.name"));
        response.put("user.dir", System.getProperty("user.dir"));
        return response;
    }
} 